import { defineStore } from 'pinia'
import { ref } from 'vue'
import { constantRoute, anyRouter, asnycRoute } from '@/router/router.ts'
import type { RouteRecordRaw } from 'vue-router'
// 用户模块
export const useUserStore = defineStore(
  'User',
  () => {
    // 定义侧边栏路由菜单
    const menuRoutes: RouteRecordRaw[] = [
      ...constantRoute,
      ...anyRouter,
      ...asnycRoute
    ]
    // 定义token
    const token = ref('')
    // 设置token
    const setToken = (newToken: string) => (token.value = newToken)
    // 返回对外暴露的变量
    return { token, setToken, menuRoutes }
  },
  { persist: true }
)
